﻿//using System;
//using System.Linq;
//using Antlr.Runtime;
//using Moq;
//using NUnit.Framework;
//using SharpTestsEx;

//namespace HQLAddin.Tests
//{
//    [TestFixture]
//    public class SyntaxErrorDetectorTests
//    {

//        [Test]
//        public void ReturnsEmptyWhenQueryIsValid()
//        {
//            var errorDetector = new SyntaxErrorDetector();
//            errorDetector.Analize("from Pop where Pop.Name = 'bcd'").Should().Be.Empty();
//        }
		
//        [Test]
//        public void ReturnsPositionInLineAndLineWhenQueryIsInvalid()
//        {
//            var errorDetector = new SyntaxErrorDetector();
//            var firstError = errorDetector.Analize("from Pop where where Pop.Name ='bcd'").First();
//            firstError.Satisfy(e => 
//                e.Span.iStartLine == 0 
//                && e.Span.iStartIndex == 15 
//                && e.Span.iEndIndex == 20
//                && e.Message.Contains("Invalid token at 'where'."));
//        }

//        [Test]
//        public void WhenParserReturnQueryExceptionThenAnalysisReturnShouldNotbeEmpty()
//        {
//            var errorDetector = new SyntaxErrorDetector();
//            errorDetector.Analize(string.Format("from MyProjectName.Domain.Entities.Category {0}c where c.", Environment.NewLine))
//                        .Should().Not.Be.Empty();
			
//        }

//        //[Test]
//        //public void WhenParserReturnQueryExceptionThenAnalysisResulShouldReflectProperty()
//        //{
//        //    var errorDetector = new SyntaxErrorDetector();
//        //    var firstReuslt = errorDetector
//        //                        .Analize(string.Format("from MyProjectName.Domain.Entities.Category {0}c where c.", Environment.NewLine))
//        //                        .First();

//        //    firstReuslt.Span.Satisfy(span => span.iStartLine == 0
//        //                                     && span.iEndLine == 1
//        //                                     && span.iStartIndex == 0
//        //                                     && span.iEndIndex == 9);

//        //}

//        [Test]
//        public void WhenRecognitionExceptionLineIsEqualsToZeroThenStartLineIsEqualsTo0()
//        {
//            var syntaxError = new SyntaxErrorDetector();
//            syntaxError.CreateSpanFromRecognitionError(new RecognitionException("a",new Exception(), new Mock<IIntStream>().Object) {Line = 0}, string.Empty)
//                        .Span.iStartLine.Should().Be.EqualTo(0);
//        }

//        [Test]
//        public void WhenRecognitionExceptionLineIsEqualsToZeroThenEndLineIsEqualsToLineCount()
//        {
//            var syntaxError = new SyntaxErrorDetector();
//            var recognitionException = new RecognitionException("a", new Exception(), new Mock<IIntStream>().Object) {  Line = 0};
//            syntaxError.CreateSpanFromRecognitionError(recognitionException, "\r\n a \r\n b")
//                        .Span.iEndLine.Should().Be.EqualTo(2);
//        }

//        [Test(Description = "The antlr exception is base 1. Not base 0 as all arrays in dot net.")]
//        public void WhenRecognitionExceptionLineIsGreaterThanZeroThenEndLineIsEqualsToLineMinusOne()
//        {
//            var syntaxError = new SyntaxErrorDetector();
//            var recognitionException = new RecognitionException("a", new Exception(), new Mock<IIntStream>().Object) { Line = 1 };
//            syntaxError.CreateSpanFromRecognitionError(recognitionException, "\r\n a \r\n b")
//                        .Span.iEndLine.Should().Be.EqualTo(0);
//        }

//        [Test]
//        public void WhenRecognitionExceptionCharPositionInLineIsEqualsToMinusOneThenStartIndexIsEqualsToZero()
//        {
//            var syntaxError = new SyntaxErrorDetector();
//            var recognitionException = new RecognitionException("a", new Exception(), new Mock<IIntStream>().Object) { CharPositionInLine  = -1 };
//            syntaxError.CreateSpanFromRecognitionError(recognitionException, "\r\n a \r\n b")
//                        .Span.iStartIndex.Should().Be.EqualTo(0);
//        }

//        [Test]
//        public void WhenRecognitionExceptionCharPositionInLineIsGreaterThanZeroThenStartIndexIsEqualsToZero()
//        {
//            var syntaxError = new SyntaxErrorDetector();
//            var recognitionException = new RecognitionException("a", new Exception(), new Mock<IIntStream>().Object) { CharPositionInLine = 3 };
//            syntaxError.CreateSpanFromRecognitionError(recognitionException, "\r\n a \r\n b")
//                        .Span.iStartIndex.Should().Be.EqualTo(3);
//        }

//        [Test]
//        public void WhenRecognitionExceptionCharPositionInLineIsLessThanZeroThenEndIndexIsEqualsToLastLineCharCount()
//        {
//            var syntaxError = new SyntaxErrorDetector();
//            var recognitionException = new RecognitionException("a", new Exception(), new Mock<IIntStream>().Object) { CharPositionInLine = -1 };
//            syntaxError.CreateSpanFromRecognitionError(recognitionException, "\r\n a \r\n b")
//                        .Span.iEndIndex.Should().Be.EqualTo(1);
//        }

//        [Test]
//        public void WhenRecognitionExceptionCharPositionInLineIsGreaterThanZeroThenEndIndexIsEqualsToCharPositionPlusOne()
//        {
//            var syntaxError = new SyntaxErrorDetector();
//            var recognitionException = new RecognitionException("a", new Exception(), new Mock<IIntStream>().Object) { CharPositionInLine = 3 };
//            syntaxError.CreateSpanFromRecognitionError(recognitionException, "\r\n a \r\n b")
//                        .Span.iEndIndex.Should().Be.EqualTo(4);
//        }

//        [Test]
//        public void WhenRecognitionExceptionCharPositionInLineIsGreaterThanZeroAndTokenTextIsNotNullThenEndIndexIsEqualsToCharPositionPlusTokenCharCount()
//        {
//            var syntaxError = new SyntaxErrorDetector();
//            var token = new Mock<IToken>();
//            token.Setup(t => t.Text).Returns("where");
//            var recognitionException = new RecognitionException(
//                "a", 
//                new Exception(),
//                new Mock<IIntStream>().Object)
//                                        {
//                                            CharPositionInLine = 3,
//                                            Token = token.Object
//                                        };

//            syntaxError.CreateSpanFromRecognitionError(recognitionException, "\r\n a \r\n b")
//                        .Span.iEndIndex.Should().Be.EqualTo(8);
//        }
//    }
//}